<?php

namespace app\task\model;

use app\common\model\gifts\UserGifts as UserGiftsModel;

/**
 * 用户优惠券模型
 * Class UserCoupon
 * @package app\task\model
 */
class UserGifts extends UserGiftsModel
{
    /**
     * 获取已过期的优惠券ID集
     * @return array
     */
    public function getExpiredGiftsIds()
    {

        $time = time();
        return $this->where('is_expire', '=', 0)
            //->where('write_status', '=', 10)
            ->where(
                "((`end_time` + 86400) < {$time} )"
            )
            ->column('user_gifts_id');
    }

    /**
     * 设置优惠券过期状态
     * @param $couponIds
     * @return false|int
     */
    public function setIsExpire($giftsIds)
    {
        if (empty($giftsIds)) {
            return false;
        }
        return $this->save(['is_expire' => 1], ['user_gifts_id' => ['in', $giftsIds]]);
    }

}
